<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="任务名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskName">
              <a-input v-model="model.taskName" placeholder="请输入任务名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="任务开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskStartDate">
              <j-date placeholder="请选择任务开始时间" v-model="model.taskStartDate" :show-time="true"
                date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="任务结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskEndDate">
              <j-date placeholder="请选择任务结束时间" v-model="model.taskEndDate" :show-time="true"
                date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="12">
            <a-form-model-item
              label="任务持续时间"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="taskDuration"
            >
             
              <a-input suffix="分钟" v-model="model.taskDuration" placeholder="请输入任务持续时间"></a-input>
            </a-form-model-item>
          </a-col>-->

          <!-- <a-col :span="24">
            <a-form-model-item
              label="指挥车入网认证码"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="ncvNetAccessAuthCode"
            >
              <a-input v-model="model.ncvNetAccessAuthCode" placeholder="请输入指挥车入网认证码"></a-input>
            </a-form-model-item>
          </a-col>-->
          <a-col :span="12">
            <!-- <a-form-model-item label="指挥车数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ncvNum">
              <a-input-number :max="4" :min="0" v-model="model.ncvNum" placeholder="请输入指挥车数量,最多4辆" style="width: 100%"
                readonly />
            </a-form-model-item> -->
          </a-col>
        </a-row>
        <a-row>
          <!-- <a-col :span="24">
            <a-form-model-item label="导弹总量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="missileTotal">
              <a-input-number v-model="model.missileTotal" placeholder="请输入导弹总量" style="width: 100%" />
            </a-form-model-item>
          </a-col>-->
          <a-col :span="12">
            <a-form-model-item label="星指上行通信速率" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="satelliteUpCvCr">
              <a-select v-model="model.satelliteUpCvCr">
                <a-select-option value="QPSK">
                  QPSK
                </a-select-option>
                <a-select-option value="BPSK">
                  BPSK
                </a-select-option>
              </a-select>
              <!-- <a-input v-model="model.satelliteUpCvCr" placeholder="请输入星指上行通信速率"></a-input> -->
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="星指下行通信速率" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="satelliteDownCvCr">
              <!-- <a-input v-model="model.satelliteDownCvCr" placeholder="请输入星指下行通信速率"></a-input> -->
              <a-select v-model="model.satelliteDownCvCr">
                <a-select-option value="QPSK">
                  QPSK
                </a-select-option>
                <a-select-option value="BPSK">
                  BPSK
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="星指上行通信频点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="satelliteUpCvCf">
              <!-- <a-input suffix="GHz" v-model="model.satelliteUpCvCf" placeholder="请输入星指上行通信频点"></a-input> -->
              <a-select default-value="30.56" style="width: 100%" v-model="model.satelliteUpCvCf">
                <a-select-option value="30.36">30.36GHz</a-select-option>
                <a-select-option value="30.56">30.56GHz</a-select-option>
                <a-select-option value="30.76">30.76GHz</a-select-option>
                <a-select-option value="30.96">30.96GHz</a-select-option>
                <a-select-option value="31.16">31.16GHz</a-select-option>
                <a-select-option value="31.36">31.36GHz</a-select-option>
                <a-select-option value="31.56">31.56GHz</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>

          <a-col :span="12">
            <a-form-model-item label="星指下行通信频点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="satelliteDownCvCf">
              <a-select default-value="20.56" style="width: 100%" v-model="model.satelliteDownCvCf">
                <a-select-option value="20.16">20.16GHz</a-select-option>
                <a-select-option value="20.36">20.36GHz</a-select-option>
                <a-select-option value="20.56">20.56GHz</a-select-option>
                <a-select-option value="20.76">20.76GHz</a-select-option>
                <a-select-option value="20.96">20.96GHz</a-select-option>
                <a-select-option value="21.16">21.16GHz</a-select-option>
                <a-select-option value="21.36">21.36GHz</a-select-option>
              </a-select>
              <!-- <a-input suffix="GHz" v-model="model.satelliteDownCvCf" placeholder="请输入星指下行通信频点"></a-input> -->
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="星指上行跳频模式" :labelCol="labelCol" :wrapperCol="wrapperCol"
              prop="satelliteUpCvCfType">
              <j-dict-select-tag type="list" v-model="model.satelliteUpCvCfType" dictCode="satellite_up_cv_cf_type"
                placeholder="请选择星指上行跳频模式" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="星指下行跳频模式" :labelCol="labelCol" :wrapperCol="wrapperCol"
              prop="satelliteDownCvCfType">
              <j-dict-select-tag type="list" v-model="model.satelliteDownCvCfType" dictCode="satellite_down_cv_cf_type"
                placeholder="请选择星指下行跳频模式" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="任务采用通信方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="communicationType">
              <a-select default-value="00" style="width: 100%" v-model="model.communicationType">
                <a-select-option value="00">明态</a-select-option>
                <a-select-option value="11">密态</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="入网认证码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="networkAccessCode">
              <a-input v-model="model.networkAccessCode" placeholder="请输入"></a-input>
            </a-form-model-item>
          </a-col>

        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="车辆识别码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="identificationCode">
              <a-input v-model="model.identificationCode" placeholder="请输入"></a-input>

            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="中频输出频率" :labelCol="labelCol" :wrapperCol="wrapperCol"
              prop="intermediateOutputFrequency">
              <j-dict-select-tag type="list" v-model="model.intermediateOutputFrequency"
                dictCode="intermediate_output_frequency" placeholder="请选择" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <!-- <a-row>
          <a-col :span="24">
            <a-form-model-item label="指控车配置">
              <create-data-modal ref="createDataModal" @count="count" @setCount="setCount" />
            </a-form-model-item>
          </a-col>
        </a-row> -->
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'
import CreateDataModal from './createDataModal.vue'

export default {
  name: 'NmcFightDemandForm',
  components: { CreateDataModal },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false,
    },
  },
  data() {
    return {
      count: 0,
      model: {
        // ncvNum: 0,
        satelliteDownCvCf: '20.56',
        satelliteDownCvCr: 'QPSK',
        satelliteDownCvCfType: 1,
        satelliteUpCvCf: '30.56',
        satelliteUpCvCr: 'QPSK',
        satelliteUpCvCfType: 1,
        communicationType: "00",
        intermediateOutputFrequency: '1.2GHz'
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 10 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 14 },
      },
      confirmLoading: false,
      validatorRules: {
        communicationType: [{ required: true, }],
        networkAccessCode: [{
          required: true, message: '请输入'
        }],
        identificationCode: [{ required: true, message: '请输入' }],
        intermediateOutputFrequency: [{ required: true, message: '请输入' }],
        taskName: [{ required: true, message: '请输入任务名称!' }],
        taskStartDate: [{ required: true, message: '请输入任务开始时间!' }],
        taskDuration: [{ required: true, message: '请输入任务持续时间!' }],
        ncvNetAccessAuthCode: [{ required: true, message: '请输入指挥车入网认证码!' }],
        missileTotal: [{ required: true, message: '请输入导弹总数' }],
        // ncvNum: [
        //   { required: true, message: '请输入指挥车数量,最小为1，最大为4!' },
        //   { pattern: /^-?\d+$/, message: '请输入整数!' },
        // ],
        satelliteDownCvCf: [{ required: true, message: '请输入星指下行通信频点!' }],
        satelliteDownCvCr: [{ required: true, message: '请输入星指下行通信速率!' }],
        satelliteDownCvCfType: [{ required: true, message: '请输入星指下行跳频模式!' }],
        satelliteUpCvCf: [{ required: true, message: '请输入星指上行通信频点!' }],
        satelliteUpCvCr: [{ required: true, message: '请输入星指上行通信速率!' }],
        satelliteUpCvCfType: [{ required: true, message: '请输入星指上行跳频模式!' }],
      },
      url: {
        add: '/fightDemand/nmcFightDemand/add',
        edit: '/fightDemand/nmcFightDemand/edit',
        queryById: '/fightDemand/nmcFightDemand/queryById',
        getByFightDemandId: "/commandVehicle/nmcCommandVehicle/getByFightDemandId"
      },
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    setCount(val) {
      this.model.ncvNum = val
      this.$set(this.model, 'ncvNum', val)
      console.log(this.model.ncvNum, 'this.count', val)
    },
    setcount(val) {
      if (val <= 4) {
        this.$refs.createDataModal.showData(this.model, 'add')
        console.log(this.$refs.createDataModal.dataSource)
      }
      // this.$refs.createDataModal.dataSource = [{}]

    },
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
      if (record.id) {
        getAction(this.url.getByFightDemandId, { fightDemandId: record.id }).then(res => {
          console.log(res, 'res')
          this.$refs.createDataModal.showData(JSON.stringify(res.result), 'edit')
        })
      }

    },
    addCreateData() { },
    submitForm() {
      const that = this
      // this.model.nmcFightDemandNcvList = this.$refs.createDataModal.dataSource
      // 触发表单验证
      console.log(this.model, 'thismodel')

      // return
      this.$refs.form.validate((valid) => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          httpAction(httpurl, this.model, method)
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        }
      })
    },
  },
}
</script>
<style>
.ant-input-affix-wrapper .ant-input-prefix,
.ant-input-affix-wrapper .ant-input-suffix {
  color: #fff !important;
}

.ant-calendar-picker-icon {
  color: #fff !important;
}
</style>
